package com.jfok.server.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.jfok.server.DAO.ModuleDAO;
import com.jfok.server.DAO.SystemBaseDAO;
import com.jfok.server.core.module.SqlModuleFilter;
import com.jfok.server.core.report.GroupFieldDefine;
import com.jfok.server.hibernate.system._MenuGroup;
import com.jfok.server.hibernate.system._MenuModule;
import com.jfok.server.hibernate.system._Module;
import com.jfok.server.hibernate.system._ModuleAdditionField;
import com.jfok.server.hibernate.system._ModuleAdditionFunction;
import com.jfok.server.hibernate.system._ModuleDetailScheme;
import com.jfok.server.hibernate.system._ModuleDetailSchemeField;
import com.jfok.server.hibernate.system._ModuleExcelRecordAdd;
import com.jfok.server.hibernate.system._ModuleExcelReport;
import com.jfok.server.hibernate.system._ModuleField;
import com.jfok.server.hibernate.system._ModuleFormScheme;
import com.jfok.server.hibernate.system._ModuleFormSchemeGroup;
import com.jfok.server.hibernate.system._ModuleFormSchemeGroupField;
import com.jfok.server.hibernate.system._ModuleGridNavigate;
import com.jfok.server.hibernate.system._ModuleGridScheme;
import com.jfok.server.hibernate.system._ModuleGridSchemeGroup;
import com.jfok.server.hibernate.system._ModuleGridSchemeGroupField;
import com.jfok.server.hibernate.system._ModuleSubToolbar;
import com.jfok.server.hibernate.system._PrintScheme;
import com.jfok.server.hibernate.system._ReportGroup;
import com.jfok.server.hibernate.systemset._Systeminfo;
import com.jfok.server.hibernate.systemset._Systemset;
import com.jfok.server.hibernate.systemset._ModuleApprove;
import com.jfok.server.hibernate.systemset._ModuleApproveUser;
import com.jfok.server.hibernate.systemset._UserFieldHiddenRoleDetail;
import com.jfok.server.hibernate.systemset._UserFieldReadonlyRoleDetail;
import com.jfok.server.hibernate.systemset._UserRoleAddition;
import com.jfok.server.hibernate.systemset._UserRoleDetail;
import com.jfok.server.logic._ModuleAdditionFieldLogic;
import com.jfok.server.login.SessionManage;
import com.jfok.server.login.UserSession;
import com.jfok.shared.ApproveListTypeEnum;
import com.jfok.shared.FieldType;
import com.jfok.shared.SystemAndLoginInfo;
import com.jfok.shared.module.ModuleConstants;
import com.jfok.shared.service.ISystemAndLoginInfoService;

@Service
public class SystemAndLoginInfoService implements ISystemAndLoginInfoService {

	private static final Log log = LogFactory.getLog(SystemAndLoginInfoService.class);
	private static boolean isRefreshAll = false;

	private static SystemBaseDAO systemBaseDAO = null;

	private static ModuleDAO moduleDAO = null;

	private static List<_Module> modules = null;

	private static ApproveService approveService = null;

	public SystemAndLoginInfoService() {
		super();
		// getModules();
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public synchronized SystemAndLoginInfo getSystemAndLoginInfo(HttpServletRequest request) {

		// 系统的属性改变了以后，只有在客户端刷新了以后才生效
		if (isRefreshAll) {
			modules = null;
			// 清除系统设置和系统信息的缓存
			SystemGlobalInfoService.refreshAll();
			// 清除所有的附加字段的缓存
			_ModuleAdditionFieldLogic.clearAllMap();
			isRefreshAll = false;
		}

		UserSession userSession = SessionManage.getInstance().getUserSession(request.getSession());
		_Systeminfo systeminfo = SystemGlobalInfoService.getSysteminfo();
		_Systemset systemset = SystemGlobalInfoService.getSystemset();
		SystemAndLoginInfo info = new SystemAndLoginInfo();

		info.setTf_systemName(systeminfo.getTf_systemName());
		info.setTf_systemVersion(systeminfo.getTf_systemVersion());
		info.setTf_systemAddition(systeminfo.getTf_systemAddition());

		info.setTf_userId(userSession.getUserId());
		info.setTf_loginName(userSession.getLoginName());
		info.setTf_userName(userSession.getUserName());
		info.setTf_departmentId(userSession.getDepartmentId());
		info.setTf_departmentName(userSession.getDepartment());

		info.setTf_userdwmc(systemset.getTf_userdwmc());
		info.setTf_userStartdate(systemset.getTf_userStartdate());
		info.setTf_serviceDepartment(systemset.getTf_serviceDepartment());
		info.setTf_serviceMen(systemset.getTf_serviceMen());
		info.setTf_serviceTelnumber(systemset.getTf_serviceTelnumber());
		info.setTf_serviceFaxnumber(systemset.getTf_serviceFaxnumber());
		info.setTf_serviceEmail(systemset.getTf_serviceEmail());
		info.setTf_serviceHomepage(systemset.getTf_serviceHomepage());
		info.setTf_serviceQQ(systemset.getTf_serviceQQ());
		info.setTf_copyrightOwner(systeminfo.getTf_copyrightOwner());
		info.setTf_copyrightInfo(systeminfo.getTf_copyrightInfo());
		info.setTf_additionFileMaxMB(systeminfo.getTf_additionFileMaxMB());
		info.setTf_previewExts(systeminfo.getTf_previewExts());

		info.setTf_MenuGroups(getMenuGroups());
		info.setTf_userRoleDetails((List<_UserRoleDetail>) systemBaseDAO.findByProperty(
				_UserRoleDetail.class, "tf_userId", userSession.getUserId()));
		info.setTf_ReportGroups((List<_ReportGroup>) getSystemBaseDAO().findAll(_ReportGroup.class));

		// 没有显示权限的模块,并且是系统模块都不进去了
		info.setTf_Modules(new HashSet<_Module>());
		for (_Module module : getModules()) {
			if (!module.getTf_isSystem())
				info.getTf_Modules().add(module);
		}
		for (_UserRoleDetail roledetail : info.getTf_userRoleDetails()) {
			if (roledetail.getTf_allowBrowse() > 0)
				info.getTf_Modules().add(getModuleWithId(roledetail.getTf_moduleId()));
			// 如果该模块有父模块，那么也将父模块的信息加入
		}
		// 这个是加全部的
		// info.setTf_Modules(getModules());

		info.setTf_userFieldHiddenRoleDetails((List<_UserFieldHiddenRoleDetail>) systemBaseDAO
				.findByProperty(_UserFieldHiddenRoleDetail.class, "tf_userId", userSession.getUserId()));

		info.setTf_userFieldReadonlyRoleDetails((List<_UserFieldReadonlyRoleDetail>) systemBaseDAO
				.findByProperty(_UserFieldReadonlyRoleDetail.class, "tf_userId", userSession.getUserId()));

		// 将每个模块具有权限的附加功能加进去
		for (_UserRoleDetail d : info.getTf_userRoleDetails())
			d.setUserRoleAdditions((List<_UserRoleAddition>) systemBaseDAO.findByString(
					_UserRoleAddition.class,
					"tf_moduleId='" + d.getTf_moduleId() + "' and tf_userId=" + d.getTf_userId()));

		userSession
				.setModuleApproveSqlFilters(new HashMap<String, Map<ApproveListTypeEnum, List<SqlModuleFilter>>>());
		// 加入操作员可以审批模块的第几级
		List<_ModuleApproveUser> users = (List<_ModuleApproveUser>) systemBaseDAO.findByProperty(
				_ModuleApproveUser.class, "tf_User.tf_userId", userSession.getUserId());
		for (_ModuleApproveUser user : users) {
			String moduleId = user.getTf_ModuleApprove().getTf_Module().getTf_moduleId();
			// 查找此操作员是否有此模块的审批权限，有再查找是第几级可以审批
			for (_UserRoleDetail d : info.getTf_userRoleDetails()) {
				if (d.getTf_moduleId().equals(moduleId) && d.getTf_allowApprove() > 0) {
					for (_UserRoleDetail userRoleDetail : info.getTf_userRoleDetails())
						if (userRoleDetail.getTf_moduleId().equals(moduleId))
							if (userRoleDetail.getTf_allowApprove() > 0) {
								// 此操作用户在该模块中是第几审批的
								userRoleDetail.setTf_approveOrder(user.getTf_ModuleApprove().getTf_order());
								userRoleDetail.setTf_approveLevel(user.getTf_ModuleApprove().getTf_level());
								_Module m = getModuleWithId(moduleId);
								userSession.getModuleApproveSqlFilters().put(
										m.getTf_moduleName(),
										getApproveService().genModuleApproveSqlFilter(m,
												user.getTf_ModuleApprove().getTf_order(), userSession.getUserName()));
							}
				}
			}
		}
		userSession.setTf_userRoleDetails(info.getTf_userRoleDetails());
		userSession.setTf_userFieldHiddenRoleDetails(info.getTf_userFieldHiddenRoleDetails());
		return info;

	}

	
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public _Module getModuleDefine(HttpServletRequest request, String moduleId, String moduleName) {

		if (moduleId != null)
			return getModuleWithId(moduleId);
		else
			return getModuleWithAsName(moduleName);
	}

	
	@SuppressWarnings("unchecked")
	public static synchronized List<_Module> getModules() {
		if (modules == null) {
			modules = getModuleDefine();
			setModuleParentAndChild(modules);
			setModuleAdditionAndSubToolbar(modules);
			setModuleApprove(modules);
			setModuleGroupFieldDefine(modules);

			// 将附加字段的信息添完整
			for (_Module module : modules) {

				// 加入自定义的grid 导航
				module.setModuleGridNavigates((List<_ModuleGridNavigate>) systemBaseDAO.findByString(
						_ModuleGridNavigate.class, "tf_moduleId='" + module.getTf_moduleId()
								+ "' and tf_enabled = 1 order by tf_order"));
				module.getModuleGridNavigates().addAll(module.getAllNavigatePaths());

				//
				for (_ModuleAdditionField field : module.getModuleAdditionFields()) {
					_ModuleField f = getModuleFieldWithId(field.getTf_fieldId());
					// if (f == null)
					// continue;
					field.setTargetModuleName(f.getTf_Module().getTf_moduleName());
					_Module m = f.getTf_Module();
					switch (field.getAggregationType()) {

					case COUNT:

						field.setTf_fieldName(ModuleConstants.COUNTAHEAD + m.getTf_moduleName());
						field.setTf_title(m.shortnameOrTitle() + "个数");
						field.setTf_fieldType(FieldType.Integer.getValue());
						field.setTf_allowSummary(true);

						break;
					case SUM:

						field.setTf_fieldName(ModuleConstants.SUMAHEAD + m.getTableAsName()
								+ ModuleConstants.SEPARATOR + f.getTf_fieldName());
						field.setTf_title(m.shortnameOrTitle() + "--" + f.getTf_title() + "小计");
						field.setTf_fieldType(f.getTf_fieldType());
						field.setTf_allowSummary(true);

						break;
					default:
						// 如果是oneToone 不管是parent 还是child 都不用sum,直接用
						field.setTf_fieldName(ModuleConstants.PARENTAHEAD + m.getTableAsName()
								+ ModuleConstants.SEPARATOR + f.getTf_fieldName());
						field.setTf_title(m.shortnameOrTitle() + "--" + f.getTf_title());
						field.setTf_fieldType(f.getTf_fieldType());

						// 如果是one to one ,那么可汇总属性跟着字段走
						if (module.isModuleParentOneToOne(m.getTf_moduleName())
								|| module.isModuleChildOneToOne(m.getTf_moduleName())) {
							field.setTf_allowSummary(f.getTf_allowSummary());
							field.setTf_title(f.getTf_title());
						} else
							field.setTf_allowSummary(false);
						break;
					}
				}
			}
		}
		return modules;
	}

	private static void setModuleGroupFieldDefine(List<_Module> modules) {
		for (_Module module : modules) {
			module.setGroupFieldDefines(new ArrayList<GroupFieldDefine>());
			for (_ModuleField field : module.getModuleFields()) {
				if (field.getTf_allowGroup()) {
					GroupFieldDefine d = new GroupFieldDefine();
					d.setModuleName(module.getTf_moduleName());
					d.setModuleTitle(module.getTf_title());
					d.setFieldId(field.getTf_fieldId());
					d.setFieldTitle(field.getTf_title());
					d.setBaseField(field.isBaseField());
					module.getGroupFieldDefines().add(d);
				}
			}
		}

		Map<_Module, ArrayList<GroupFieldDefine>> groups = new HashMap<_Module, ArrayList<GroupFieldDefine>>();

		for (_Module module : modules) {
			ArrayList<GroupFieldDefine> define = new ArrayList<GroupFieldDefine>();
			define.addAll(module.getGroupFieldDefines());
			groups.put(module, define);

			for (_Module pm : module.getAllParentsList()) {
				define.addAll(pm.getGroupFieldDefines());
			}

		}

		for (_Module module : modules) {
			module.setGroupFieldDefines(groups.get(module));
		}

	}

	// 生成每个模块的id name map ，可以被子模块用来选择
	// private Map<String, Map<String, String>> getModuleIdNameMap(List<_Module>
	// modules,
	// HttpServletRequest request) {
	//
	// Map<String, Map<String, String>> moduleidmaps = new HashMap<String,
	// Map<String, String>>();
	// for (_Module module : modules)
	// if (module.getTf_needIdNameMap())
	// moduleidmaps.put(module.getTf_moduleName(),
	// getModuleDAO().getModuleWithTreeData(module.getTf_moduleName(), null,
	// request));
	// return moduleidmaps;
	// }

	@SuppressWarnings("unchecked")
	private synchronized static void setModuleAdditionAndSubToolbar(List<_Module> modules2) {
		for (_Module module : modules) {
			List<_ModuleAdditionFunction> additions = (List<_ModuleAdditionFunction>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleAdditionFunction.class, "tf_moduleAdditionFunctionId",
							"asc", "tf_Module.tf_moduleId", module.getTf_moduleId(), null, null);
			module.setModuleAdditions(additions);
			
			List<_ModuleSubToolbar> subtoolbar = (List<_ModuleSubToolbar>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleSubToolbar.class, "tf_order",
							"asc", "tf_Module.tf_moduleId", module.getTf_moduleId(), null, null);
			module.setModuleSubToolbar(subtoolbar);
		}
	}

	@SuppressWarnings("unchecked")
	private synchronized static void setModuleApprove(List<_Module> modules) {
		for (_Module module : modules) {
			if (module.getTf_hasApprove())
				module.setModuleApproves((List<_ModuleApprove>) getSystemBaseDAO().findByPropertyAllSort(
						_ModuleApprove.class, "tf_order", "asc", "tf_Module.tf_moduleId",
						module.getTf_moduleId(), null, null));
		}

	}

	
	public static _ModuleField getModuleFieldWithId(Integer fieldid) {
		for (_Module module : getModules())
			for (_ModuleField field : module.getModuleFields())
				if (field.getTf_fieldId().equals(fieldid)) {
					field.setTf_Module(module);
					return field;
				}
		return null;
	}

	// 根据模块id号取得模块定义
	public static _Module getModuleWithId(String id) {
		for (_Module module : getModules())
			if (module.getTf_moduleId().equals(id))
				return module;
		return null;
	}

	// 根据模块 name 号取得模块定义
	public static _Module getModuleWithName(String name) {
		for (_Module module : getModules())
			if (module.getTf_moduleName().equals(name))
				return module;
		return null;
	}

	// 根据模块 as name 号取得模块定义
	public static _Module getModuleWithAsName(String name) {
		for (_Module module : getModules())
			if (module.getTableAsName().equals(name))
				return module;
		return null;
	}

	
	private static void setModuleParentAndChild(List<_Module> modules) {
		for (_Module module : modules) {
			// 对于每一个字段，查找其字段类型是另一个Module名，如果是的话，那么此为其父类
			for (_ModuleField field : module.getModuleFields()) {
				String fieldType = field.getTf_fieldType();
				for (_Module parentmodule : modules)
					// 检查每一个模块，是否有此模块的父模块
					if (fieldType.equals(parentmodule.getTf_moduleName())) {
						
						if (field.isManyToOne() || field.isOneToOne()) {
							
							//如果是one to one 那么，也把其加入到 par里面去

							module.getParents().add(parentmodule);
							log.debug(module.getTf_title() + "找到父模块:" + parentmodule.getTf_title());
							parentmodule.getChilds().add(module);
							parentmodule.getChildNames().add(module.getTf_moduleName());
						};
						
						if (field.isOneToOne()) {
							
							module.getParentOneToOnes().add(parentmodule);
							log.debug(module.getTf_title() + "找到onetoone模块:" + parentmodule.getTf_title());
							parentmodule.getChildOneToOnes().add(module);
							parentmodule.getChildNames().add(module.getTf_moduleName());
						}
					}
			}
		}

		// 将所有的可以加入navigate的模块的模块加好
		for (_Module module : modules) {
			// 对于每一个字段，查找其字段类型是另一个Module名，如果是的话，那么此为其父类
			for (_ModuleField field : module.getModuleFields()) {
				String fieldType = field.getTf_fieldType();
				for (_Module parentmodule : modules)
					// 检查每一个模块，是否有此模块的父模块,并且要将此字段设置为可以显示在导航树
					if (field.getTf_showNavigatorTree() && fieldType.equals(parentmodule.getTf_moduleName())) {
						module.getNavigateParents().add(parentmodule);
					}
			}
		}

	}

	

	@SuppressWarnings("unchecked")
	private static List<_MenuGroup> getMenuGroups() {
		List<_MenuGroup> menuGroups = (List<_MenuGroup>) getSystemBaseDAO().findAll(_MenuGroup.class);
		for (_MenuGroup group : menuGroups) {
			List<_MenuModule> menuModules = (List<_MenuModule>) getSystemBaseDAO().findByPropertyAllSort(
					_MenuModule.class, "tf_orderId", "asc", "tf_MenuGroup.tf_menuGroupId",
					group.getTf_menuGroupId(), null, null);
			group.setTf_menuModules(menuModules);
		}
		return menuGroups;
	}

	
	@SuppressWarnings("unchecked")
	private synchronized static List<_Module> getModuleDefine() {
		List<_Module> modules = (List<_Module>) getSystemBaseDAO().findAll(_Module.class);
		// 下面加入字段，列表，以有 form
		for (_Module module : modules) {
			// 加入模块的字段
			module.setModuleFields((List<_ModuleField>) getSystemBaseDAO().findByPropertyAllSort(
					_ModuleField.class, "tf_fieldOrder", "asc", "tf_Module.tf_moduleId",
					module.getTf_moduleId(), null, null));
			// 加入模块的附加字段
			module.setModuleAdditionFields((List<_ModuleAdditionField>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleAdditionField.class, "tf_fieldId", "asc", "tf_moduleId",
							module.getTf_moduleId(), null, null));
			// 加入模块fom方案
			module.setModuleFormSchemes((List<_ModuleFormScheme>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleFormScheme.class, "tf_schemeOrder", "asc",
							"tf_Module.tf_moduleId", module.getTf_moduleId(), null, null));
			// 加入record 打印 方案
			module.setRecordPrintSchemes((List<_PrintScheme>) getSystemBaseDAO().findByPropertyAllSort(
					_PrintScheme.class, "tf_schemeOrder", "asc", "tf_Module.tf_moduleId",
					module.getTf_moduleId(), null, null));

			for (_ModuleFormScheme scheme : module.getModuleFormSchemes()) {
				// 加入form下的字段分组
				scheme.setModuleFormSchemeGroups((List<_ModuleFormSchemeGroup>) getSystemBaseDAO()
						.findByPropertyAllSort(_ModuleFormSchemeGroup.class, "tf_formGroupOrder", "asc",
								"tf_ModuleFormScheme.tf_formSchemeId", scheme.getTf_formSchemeId(), null, null));
				for (_ModuleFormSchemeGroup schemeGroup : scheme.getModuleFormSchemeGroups()) {
					// 加入每个字段分组下的字段
					schemeGroup
							.setModuleFormSchemeGroupFields((List<_ModuleFormSchemeGroupField>) getSystemBaseDAO()
									.findByPropertyAllSort(_ModuleFormSchemeGroupField.class, "tf_formFieldOrder",
											"asc", "tf_ModuleFormSchemeGroup.tf_formGroupId",
											schemeGroup.getTf_formGroupId(), null, null));
				}
			}

			// 加入模块gird方案
			module.setModuleGridSchemes((List<_ModuleGridScheme>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleGridScheme.class, "tf_schemeOrder", "asc",
							"tf_Module.tf_moduleId", module.getTf_moduleId(), null, null));
			for (_ModuleGridScheme scheme : module.getModuleGridSchemes()) {
				// 加入grid下的字段分组
				scheme.setModuleGridSchemeGroups((List<_ModuleGridSchemeGroup>) getSystemBaseDAO()
						.findByPropertyAllSort(_ModuleGridSchemeGroup.class, "tf_gridGroupOrder", "asc",
								"tf_ModuleGridScheme.tf_gridSchemeId", scheme.getTf_gridSchemeId(), null, null));
				for (_ModuleGridSchemeGroup schemeGroup : scheme.getModuleGridSchemeGroups()) {
					// 加入每个字段分组下的字段

					List<_ModuleGridSchemeGroupField> gfs = (List<_ModuleGridSchemeGroupField>) getSystemBaseDAO()
							.findByPropertyAllSort(_ModuleGridSchemeGroupField.class, "tf_gridFieldOrder", "asc",
									"tf_ModuleGridSchemeGroup.tf_gridGroupId", schemeGroup.getTf_gridGroupId(), null,
									null);
					if (gfs != null)
						schemeGroup.setModuleGridSchemeGroupFields(gfs);
				}
			}

			// 加入模块 detail 方案
			module.setModuleDetailSchemes((List<_ModuleDetailScheme>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleDetailScheme.class, "tf_order", "asc",
							"tf_Module.tf_moduleId", module.getTf_moduleId(), null, null));
			for (_ModuleDetailScheme scheme : module.getModuleDetailSchemes()) {
				// 加入detail下的字段分组
				scheme.setModuleDetailSchemeFields((List<_ModuleDetailSchemeField>) getSystemBaseDAO()
						.findByPropertyAllSort(_ModuleDetailSchemeField.class, "tf_order", "asc",
								"tf_ModuleDetailScheme.tf_detailId", scheme.getTf_detailId(), null, null));
			}

			// 加入 module excel report 的定义
			module.setModuleExcelReports((List<_ModuleExcelReport>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleExcelReport.class, "tf_order", "asc",
							"tf_Module.tf_moduleId", module.getTf_moduleId(), null, null));

			// 加入 module 单条记录 excel 导入的设置
			module.setModuleExcelRecordAdds((List<_ModuleExcelRecordAdd>) getSystemBaseDAO()
					.findByPropertyAllSort(_ModuleExcelRecordAdd.class, "tf_order", "asc",
							"tf_Module.tf_moduleId", module.getTf_moduleId(), null, null));

		}
		return modules;
	}

	public static boolean isRefreshAll() {
		return isRefreshAll;
	}

	public static void setRefreshAll(boolean isRefreshAll) {
		SystemAndLoginInfoService.isRefreshAll = isRefreshAll;
	}

	public static ApproveService getApproveService() {
		if (approveService == null)
			setApproveService((ApproveService) SystemGlobalInfoService.getBean(ApproveService.class));
		return approveService;
	}

	public static void setApproveService(ApproveService approveService) {
		SystemAndLoginInfoService.approveService = approveService;
	}

	public static SystemBaseDAO getSystemBaseDAO() {
		if (systemBaseDAO == null)
			setSystemBaseDAO((SystemBaseDAO) SystemGlobalInfoService.getBean(SystemBaseDAO.class));
		return systemBaseDAO;
	}

	public static void setSystemBaseDAO(SystemBaseDAO systemBaseDAO) {
		SystemAndLoginInfoService.systemBaseDAO = systemBaseDAO;
	}

	public static ModuleDAO getModuleDAO() {
		if (moduleDAO == null)
			setModuleDAO((ModuleDAO) SystemGlobalInfoService.getBean(ModuleDAO.class));
		return moduleDAO;
	}

	public static void setModuleDAO(ModuleDAO moduleDAO) {
		SystemAndLoginInfoService.moduleDAO = moduleDAO;
	}

}
